<?php
// +----------------------------------------------------------------------
// | 07FLYSAAS [基于ThinkPHP5.0开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2025-2035 http://www.07fly.xyz
// +----------------------------------------------------------------------
// | Professional because of focus  Persevering because of happiness
// +----------------------------------------------------------------------
// | Author: 开发人生 <goodkfrs@qq.com>
// +----------------------------------------------------------------------

namespace app\plat\logic;

use think\Db;

/**
 * 系统消息逻辑
 */
class TenMsgType extends PlatBase
{
    /**
     * 获取消息列表
     */
    public function getTenMsgTypeList($where = [], $field = true, $order = 'id desc', $paginate = DB_LIST_ROWS)
    {
        $list = $this->modelTenMsgType->getList($where, true, 'create_time desc', $paginate);
        return $list;
    }

    /**
     * 消息删除
     */
    public function getTenMsgTypeInfo($where = [])
    {
        return $this->modelTenMsgType->getInfo($where, true);
    }

    /**
     * 消息删除
     */
    public function tenMsgTypeDel($where = [])
    {
        return $this->modelTenMsgType->deleteInfo($where, true) ? [RESULT_SUCCESS, '删除成功'] : [RESULT_ERROR, $this->modelTenMsgType->getError()];
    }

    /**
     * 更新修改
     * @param array $data
     * @return array
     * Author: 开发人生 goodkfrs@qq.com
     * Date: 2021/9/8 0008 10:25
     */
    public function tenMsgTypeAdd($data = [])
    {
        $validate_result = $this->validateTenMsgType->scene('add')->check($data);
        if (!$validate_result) {
            return [RESULT_ERROR, $this->validateTenMsgType->getError()];
        }
        $result = $this->modelTenMsgType->setInfo($data);
        $result && ten_log('添加', 'name：' . $data['name']);
        $url = url('show');
        return $result ? [RESULT_SUCCESS, '添加成功', $url] : [RESULT_ERROR, $this->modelTenMsgType->getError()];
    }

    /**
     * 更新修改
     * @param array $data
     * @return array
     * Author: 开发人生 goodkfrs@qq.com
     * Date: 2021/9/8 0008 10:25
     */
    public function tenMsgTypeEdit($data = [])
    {
        $validate_result = $this->validateTenMsgType->scene('edit')->check($data);
        if (!$validate_result) {
            return [RESULT_ERROR, $this->validateTenMsgType->getError()];
        }
        $url = url('show');
        $result = $this->modelTenMsgType->setInfo($data);
        $result && ten_log('编辑', 'name：' . $data['name']);
        return $result ? [RESULT_SUCCESS, '编辑成功', $url] : [RESULT_ERROR, $this->modelTenMsgType->getError()];
    }

    /**
     * 获取列表搜索条件
     */
    public function getWhere($data = [])
    {
        $where = [];
        //关键字查
        !empty($data['keywords']) && $where['name|remark|type|remark'] = ['like', '%' . $data['keywords'] . '%'];
        if (!empty($data['status'])) {
            $where['status'] = ['=', '' . $data['status'] . ''];
        }
        return $where;
    }

    /**
     * 获取排序条件
     */
    public function getOrderBy($data = [])
    {
        $order_by = "";
        //排序操作
        if (!empty($data['orderField'])) {
            $orderField = $data['orderField'];
            $orderDirection = $data['orderDirection'];
            switch ($orderField) {
                case 'by_create_time':
                    $order_by = "a.create_time $orderDirection";
                    break;
                case 'by_name':
                    $order_by = "a.name $orderDirection";
                    break;
                case 'by_url':
                    $order_by = "a.url $orderDirection";
                    break;
                default:
                    $order_by = "a.create_time asc";
                    break;
            }
        }
        return $order_by;
    }

}